The IDL_VARIABLE Structure
IDL variables are represented by IDL_VARIABLE structures. The definition of IDL_VARIABLE is as follows:
typedef struct {
UCHAR type;
UCHAR flags;
IDL_ALLTYPES value;
} IDL_VARIABLE;
An IDL_VPTR is a pointer to an IDL_VARIABLE structure:
typedef IDL_VARIABLE *IDL_VPTR;
The IDL_ALLTYPES union is defined as:
typedef union {
UCHAR c; /* Scalar IDL_TYP_BYTE */
IDL_INT i; /* Scalar IDL_TYP_INT */
IDL_UINT ui; /* Unsigned short integer value */
IDL_LONG l; /* Scalar IDL_TYP_LONG */
IDL_ULONG ul; /* Unsigned long value */
IDL_LONG64 l64; /* 64-bit integer value */
IDL_ULONG64 ul64; /* Unsigned 64-bit integer value */
float f; /* Scalar IDL_TYP_FLOAT */
double d; /* Scalar IDL_TYP_DOUBLE */
IDL_COMPLEX cmp; /* Scalar IDL_TYP_COMPLEX */
IDL_DCOMPLEX dcmp; /* Scalar IDL_TYP_DCOMPLEX */
IDL_STRING str; /* Scalar IDL_TYP_STRING */
IDL_ARRAY *arr; /* Pointer to array descriptor */
IDL_SREF s; /* Structure descriptor */
IDL_HVID hvid; /* Heap variable identifier */
}IDL_ALLTYPES;
The basic scalar types are contained directly in this union, while arrays and structures are represented by the IDL_ARRAY and IDL_SREF structures that are discussed later in this chapter. The type field of the IDL_VARIABLE structure contains one of the type codes discussed in Types. When a variable is initially created, it is given the type code IDL_TYP_UNDEF, indicating that the variable contains no value.
The flags field is a bit mask that specifies information about the variable. As a programmer adding code to the IDL system, you will rarely need to set bits in this mask. These bits are set by whatever portion of IDL created the variable. You can check them to make sure the characteristics of the variable fit the requirements of your routine (see Checking Arguments).
The defined bits in the mask are:
IDL_V_CONST
If this flag is set, the variable is actually a constant. This means that storage for the IDL_VARIABLE resides inside the code section of the user procedure or function that used it. The IDL compiler generates such IDL_VARIABLEs when an expression involving a constant occurs. For example, the IDL statement:
PRINT, 23 * A
causes the compiler to generate a constant for the “23”. You must not change the value of this type of “variable.”
IDL_V_TEMP
If this flag is set, the variable is a temporary variable. IDL maintains a pool of nameless IDL_VARIABLEs that can be checked out and returned as needed. Such variables are used by the interpreter to temporarily store the results of expressions on the stack. For example, the statement:
PRINT, 2 * 3
will cause the interpreter to go through a sequence of events similar to:
- Push a constant variable for the 2 on the stack.
- Push a constant variable for the 3 on the stack.
- Allocate a temporary variable, pop the two constants from the stack, perform the multiplication with the result going into the temporary variable.
- Push the temporary variable onto the stack.
- Call the PRINT system procedure specifying one argument.
- Remove the argument to PRINT from the stack, and return the temporary variable.
Temporary variables are also used inside user procedures and functions. See Temporary Variables .
IDL_V_ARR
If this flag is set, the variable is an array, and the value field of the IDL_VARIABLE points to an array descriptor.
IDL_V_FILE
If this flag is set, the variable is a file variable, as created by IDL’s ASSOC function.
IDL_V_DYNAMIC
If this flag is set, the memory used by this IDL_VARIABLE is dynamically allocated. This bit is set for arrays, structures, and for variables of IDL_TYP_STRING (because the memory referenced via the string pointer is dynamic).
IDL_V_STRUCT
If this flag is set, the variable is a structure, and the value field of the IDL_VARIABLE points to the structure descriptor. For implementation reasons, all structure variables are also arrays, so IDL_V_STRUCT also implies IDL_V_ARR. Therefore, it is impossible to have a scalar structure. However, single-element structure arrays are quite common.
Because structure variables have their type field set to IDL_TYP_STRUCT, the IDL_V_STRUCT bit is redundant. It exists for efficiency reasons.